/**
 * 
 */
package speculoos.valid;

import java.util.Map;

import speculoos.core.Mapper;

/**
 * Base interface for input validation rules.
 * A validator is basically a {@see speculoos.core.Mapper} that:
 * <ul>
 * <li>Return passed object asis if validation succeeds,</li>
 * <li>Throw an exception if validation fails.</li>
 * </ul> 
 * 
 * @author nono
 * @version $Id$
 */
public interface Validator extends Mapper {

	/**
	 * A validator that accepts any input in any environment.
	 */
	public static final Validator ACCEPT = new Validator() {
	
		public Object map(Object input, Map env) {
			// do nothing
			return input;
		}

		public String getName() {
			return "AcceptValidator";
		}
	};
	
	/**
	 * A validator that refuses any input in any environment.
	 */
	public static final Validator DENY = new Validator(){
	
		public Object map (Object input, Map env) throws InvalidateException {
			// thorw excepction
			throw new InvalidateException(getName());
		}

		public String getName() {
			return "DenyValidator";
		}
	
	};
	
	/*
	 *  (non-Javadoc)
	 * @see speculoos.core.Mapper#map(java.lang.Object, java.util.Map)
	 */
	Object map (Object input, Map env) throws InvalidateException;
	
}
